<?php
#####################################
# * @Author: lehieu008              #
# * @Email: lehieu008@gmail.com     #
# * @Copyright: 2008 - 2010         #
#####################################
if(!defined('BASEPATH'))exit('No direct script access allowed');
class Ads_module extends Controller
{
    function __construct()
    {
        parent::Controller();
    }
    
    function vip($home = true)
    {
        if($home == true)
        {
            $limit = 10;
            $sql = "SELECT adsID, adsSection, adsCategory, adsTitle, adsDetail, adsView FROM {PRE}ads ";
        }
        else
        {
            $limit = VIP_ADS_ROWS;
            $sql = "SELECT adsID, adsSection, adsCategory, adsTitle, adsDetail, adsView, adsPostDate, preName FROM {PRE}ads ";
            $sql .= "INNER JOIN {PRE}province ON {PRE}ads.adsProvince = {PRE}province.preID ";
        }
        $sql .= "WHERE adsStatus = 1 AND adsVip >= ".time()." AND adsExpireDate >= ".time()." ";
        $sql .= "ORDER BY RAND() LIMIT 0,$limit";
        $data['rows'] = $this->global_model->fetch($sql);
        $data['home'] = $home;
        #Load View
        $this->load->view('ads/vip', $data);
    }
    
    function bestshop()
    {
        $sql = "SELECT adsID, adsSection, adsCategory, adsTitle, adsDetail, adsView, adsPostDate FROM {PRE}ads ";
        $sql .= "INNER JOIN {PRE}user ON {PRE}ads.adsUser = {PRE}user.useID ";
        $sql .= "WHERE adsStatus = 1 AND useGroup = 3 AND useExpireDate >= ".time()." AND adsExpireDate >= ".time()." ";
        $sql .= "ORDER BY RAND() LIMIT 0,".ADS_MODULE_ROWS;
        $data['rows'] = $this->global_model->fetch($sql);
        #Load View
        $this->load->view('ads/vip', $data);
    }
    
    function viewest()
    {
        $sql = "SELECT adsID, adsSection, adsCategory, adsTitle, adsDetail, adsView, adsPostDate FROM {PRE}ads ";
        $sql .= "WHERE adsStatus = 1 AND adsExpireDate >= ".time()." ";
        $sql .= "ORDER BY adsView DESC LIMIT 0,".ADS_MODULE_ROWS;
        $data['rows'] = $this->global_model->fetch($sql);
        #Load View
        $this->load->view('ads/viewest', $data);
    }
    
    function user($user = 0, $current = 0)
    {
        $sql = "SELECT adsID, adsSection, adsCategory, adsTitle, adsDetail, adsView, adsPostDate FROM {PRE}ads ";
        $sql .= "WHERE adsUser = $user AND adsID != $current AND adsStatus = 1 AND adsExpireDate >= ".time()." ";
        $sql .= "ORDER BY RAND() LIMIT 0,".ADS_MODULE_ROWS;
        $data['rows'] = $this->global_model->fetch($sql);
        #Load View
        $this->load->view('ads/user', $data);
    }
    
    function category($category = 0, $current = 0)
    {
        $sql = "SELECT adsID, adsSection, adsCategory, adsTitle, adsDetail, adsView, adsPostDate FROM {PRE}ads ";
        $sql .= "WHERE adsCategory = $category AND adsID != $current AND adsStatus = 1 AND adsExpireDate >= ".time()." ";
        $sql .= "ORDER BY RAND() LIMIT 0,".ADS_MODULE_ROWS;
        $data['rows'] = $this->global_model->fetch($sql);
        #Load View
        $this->load->view('ads/category', $data);
    }
}